<?php
require_once 'SessionAuth.class.php';

$auth = new SessionAuth();
$status = $auth->getLoginStatus();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户状态</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .status-container {
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            width: 400px;
            text-align: center;
        }
        .success {
            color: #155724;
            background-color: #d4edda;
            border: 1px solid #c3e6cb;
            padding: 15px;
            border-radius: 4px;
        }
        .error {
            color: #721c24;
            background-color: #f8d7da;
            border: 1px solid #f5c6cb;
            padding: 15px;
            border-radius: 4px;
        }
        .user-info {
            text-align: left;
            background: #f8f9fa;
            padding: 15px;
            border-radius: 4px;
            margin: 15px 0;
        }
        .btn {
            display: inline-block;
            padding: 10px 20px;
            background-color: #007bff;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            margin: 5px;
        }
        .btn:hover {
            background-color: #0056b3;
        }
        .btn-logout {
            background-color: #dc3545;
        }
        .btn-logout:hover {
            background-color: #c82333;
        }
    </style>
</head>
<body>
    <div class="status-container">
        <h2>用户登录状态</h2>
        
        <?php if ($status['logged_in']): ?>
            <div class="success">
                <h3>✅ 登录成功!</h3>
            </div>
            <div class="user-info">
                <p><strong>用户名:</strong> <?php echo htmlspecialchars($status['username']); ?></p>
                <p><strong>登录时间:</strong> <?php echo $status['login_time']; ?></p>
                <p><strong>登录IP:</strong> <?php echo $status['ip']; ?></p>
            </div>
            <div>
                <a href="login.html" class="btn">返回登录页</a>
                <a href="logout.php" class="btn btn-logout">退出登录</a>
            </div>
        <?php else: ?>
            <div class="error">
                <h3>❌ <?php echo $status['message']; ?></h3>
            </div>
            <div>
                <a href="login.html" class="btn">前往登录</a>
            </div>
        <?php endif; ?>
    </div>
</body>
</html>